from django.shortcuts import render
from rest_framework.views import APIView
from rest_framework.response import Response
from .models import Carousel,Category,Goods,HotGoods
from .serializers import CarouselSer,GoodsSer,HotGoodsSer


# Create your views here.
# 轮播图
class CarouselView(APIView):
    def get(self,request):
        cars = Carousel.objects.all()
        cser = CarouselSer(cars,many=True)
        return Response({"resultCode":200,'carousels':cser.data})


# 主页商品
class GoodsAPIView(APIView):
    def get(self,request):
        goods = HotGoods.objects.all()
        goods_ser = HotGoodsSer(goods,many=True)
        return Response({"resultCode":200,'hot_goods':goods_ser.data})


# 新商品
class NewAPIView(APIView):
    def get(self,request):
        goods = Goods.objects.all()
        goods_ser = GoodsSer(goods,many=True)
        return Response({"resultCode":200,'new_goods':goods_ser.data})

# 最新推荐
class WseAPIView(APIView):
    def get(self,request):
        goods = Goods.objects.all()
        goods_ser =GoodsSer(goods,many=True)
        return Response({"resultCode":200,'wse_goods':goods_ser.data})